package com.infore.airsupervise.adapter;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.infore.airsupervise.R;
import com.infore.airsupervise.bean.EventE;


import java.util.List;

/**
 * Created by junweiliu on 16/5/31.
 */
public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder>{
    private List<EventE> list;

    public SearchAdapter(List<EventE> list){
        this.list=list;
    }

    public void addData(List<EventE> mDatas){

            list.addAll(mDatas);
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }
    @Override
    public int getItemViewType(int position) {
        EventE item=list.get(position);
        if(!item.getFlag().equals("")&&item.getFlag().equals("3")){
            return 2;
        }
        return 1;
    }

    @Override
    public SearchAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SearchAdapter.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_event_item, parent, false));
    }

    @Override
    public void onBindViewHolder(SearchAdapter.ViewHolder holder, int position) {
        holder.title.setText(list.get(position).getEventName());


        holder.modify.setImageResource(R.drawable.event_modify);
        holder.desc.setText(list.get(position).getDescriptions());
        holder.time.setText(list.get(position).getEventTime());

        if(list.get(position).getFlag().equals("0")){
            holder.handler.setText("未处理");
            holder.modify.setImageResource(R.drawable.event_modify);
        }else if(list.get(position).getFlag().equals("1")){
            holder.handler.setText("处理中");
            holder.modify.setImageResource(R.drawable.event_modify);
        }else{
            holder.handler.setText("已完成");
        }

    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView title;
        ImageView modify;
        TextView desc;
        TextView handler;
        TextView time;
        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.event_item_title);
            modify = (ImageView) itemView.findViewById(R.id.event_item_modify);
            desc = (TextView) itemView.findViewById(R.id.event_item_desc);
            handler = (TextView) itemView.findViewById(R.id.event_item_handler);
            time = (TextView) itemView.findViewById(R.id.event_item_time);

        }

    }

}
